#pragma once


typedef std::list<POINT> points;
typedef std::list<points *> lines;
typedef points::iterator pointiterator;
typedef lines::iterator  lineiterator;


#define POINT_LIMIT 20

typedef  struct  tagfigure2file
{ 
    struct _info{
        char inf[8];
        int _no;
    };
  
    _info structure[3];
  /*
  CHAR info1[8]; //FIGURE:
  int   figureNo;
  CHAR info2[8];//POINT_X:
  int   point_x;
  CHAR info3[8];//POINT_Y:
  int   point_y;
  */
} figure2file, * pfigure2file;

#ifdef MATH_API
  class MATH_API _cursor
#else
  class _cursor
#endif
{
private:
  RECT  _rgn;
public:
  RECT  _rct;
  POINT _pt;

  POINT & GetMax();
  POINT & GetMin();
  RECT  & GetReg();
 // bool operator != (_cursor *);
};

/*
#ifdef MATH_API
  struct MATH_API PN
#else
  class PN
#endif
{
  COLORREF _color;
  int      _style;
  int      _width;
  HPEN      _oldpen;
  HBRUSH    _oldbrush;
};
*/

//class figure will kept all points of interested figure
//so it will be easily redrawed 
#ifdef MATH_API
  class MATH_API CFigure2D
#else
  class CFigure2D
#endif
{
protected:
    points *        m_points; 
    lines  *        m_lines;
    pointiterator * m_pointiterator;
    pointiterator   m_ptIter;
    lineiterator  * m_lineiterator;
    int             m_npoints;
    bool            m_serialize;
    HWND            m_hwnd;
public:
    CFigure2D();
    ~CFigure2D();
    int     AddPoint(POINT &);
    POINT & GetFirstPoint();
    POINT & GetNextPoint();
    POINT & GetPrevPoint();
    POINT & GetLastPoint();
    void UpdatePoint(POINT &, int);
    void BeginLine();
    void EndLine();
    int GetSize();
    bool IsPointInside(const POINT &);
//*****Virtual methods    
    virtual void RemoveCurrentFigure();
    virtual void DrawFigure(const HWND &, bool _bCoordinates = true);
    virtual void DrawFigure(const HWND &, HDC &, bool _bCoordinates = true);
    virtual void ShowPicture(HWND &);
    virtual bool Serialize(bool);
    virtual bool GetCirculation();
    virtual void CleanPoints();
    virtual bool IsEdgeIntersect();
    virtual bool IsClosedLine();
protected:
    virtual void InitPen(COLORREF &);
    virtual void CheckCloseLine(POINT & point);
    virtual void EliminateSubPoints(); //Remove points layed on the same vector/line
};